<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="Arithmetic.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	request.setCharacterEncoding("UTF-8");
	int number = Integer.parseInt(request.getParameter("number"));
	String[][] formulas =new String[number][4];
	for (int i = 0; i < number; i++) {
		 formulas[i] = ArithmeticFunc.CreateFormulaRandom();

	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>四则运算</title>
<link rel="stylesheet" type="text/css" href="./css/reset.css"></link>
<link rel="stylesheet" type="text/css" href="./css/body.css">
<link />
<script>
    function check()
    {
    	var jsnum=<%=number%>;
	    for(var i=0;i<jsnum;i++)
	    {
	    	var resinputid="re"+i;
	    	var res=document.getElementById(resinputid).value;
	    	if( res==null ||res=="")
	    	{
	    		alert("请输入合法的数字");
	            document.getElementById(resinputid).focus();
	    	}
	    		
	    }
	    
	    showResult();
	}
    
	function empty()//清空輸入的數據
	{
		document.getElementById("al").value = "";
	}
	
	function showResult()
	{
		
		var jsresultArr = new Array(100);
		var jsnum=<%=number%>;
		<%
		for(int i=0;i<number;i++){
		%>
			jsresultArr[<%=i%>]='<%=formulas[i][3]%>';  //调试了一个下午啊
		<%}
		%>
		var count=0;
		for(var i=0;i<jsnum;i++){
			var resinputid="re"+i;
			var restick="tick"+i;
			var resultinput=document.getElementById(resinputid).value+"";
			if(resultinput==jsresultArr[i]){
				count++;
				document.getElementById(restick).innerHTML="对";
			}
			else{
				document.getElementById(restick).innerHTML="错";
			}
			
		}
		
		 var RB=1.0*count/jsnum+"";
		document.getElementById("showRightRate").innerHTML="正确率:"+(RB.substring(0,RB.indexOf(".") + 3));
	}
</script>
</head>
<body>
	<center>
		<form action="getProblem.jsp" method="get">
			<table id="thistable">
				<tr>
					<td width="280pt">题目数</td>
					
				</tr>
				<tr>
					<td><input id="a1" name="number" type="text" value=<%=number%>
						onkeyup="this.value=this.value.replace(/\D/g,'')"></td>
				</tr>
				<tr>
					<td><input id="pacman1" type="submit" value="送"></td>
				</tr>
			</table>
		</form>
		<div>
			<table>
				<%
					for (int i = 0; i < number; i++) {
				%>
				<tr>
					<td><%=formulas[i][0]%></td>
					<td><%=formulas[i][1]%></td>
					<td><%=formulas[i][2]%></td>
					<td>=</td>
					<td><input type="text" id=<%="re" + i%>></td>
					<td id=<%="tick" + i%>></td>
				</tr>
				<%
					}
				%>
				<tr>
					<td>
						<button id="pacman2" type="button" onclick="check()">交</button>
					</td>
				</tr>
			</table>
		</div>
		<div id="showRightRate"></div>
	</center>
</body>
</html>
